package com.java;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;

class Record implements Comparable<Record>{
    private String jobId;
    private int count;

    public Record(String job_id, int count) {
        this.jobId = job_id;
        this.count = count;
    }

    public String getJobId() {
        return jobId;
    }

    public void setJob_id(String jobId) {
        this.jobId = jobId;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public String toString() {
        return "Record{" +
                "jobId='" + jobId + '\'' +
                ", count=" + count +
                '}';
    }

    @Override
    public int compareTo(Record o) {
        return o.count-this.count;
    }
}

public class StreamTests {
    public static void main(String[] args) {
        List<Record> list=new ArrayList<>();
        list.add(new Record("A", 10));
        list.add(new Record("B", 30));
        list.add(new Record("C", 5));
        list.add(new Record("D", 60));
        //方案1：
//        Collections.sort(list);
//        for(Record r:list){
//            System.out.println(r);
//        }

        //方案2:
//        list.sort(new Comparator<Record>() {
//            @Override
//            public int compare(Record o1, Record o2) {
//                return o2.getCount()-o1.getCount();
//            }
//        });
//        list.sort((o1,o2)->{
//            return o2.getCount()-o1.getCount();
//        });
//        System.out.println(list);

         //方案3：

        list.stream().sorted((o1,o2)-> o2.getCount()-o1.getCount())
                     .forEach(System.out::println);



    }
}
